package com.dd.edu.multifile;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class MultiFileDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        job.setJarByClass(MultiFileDriver.class);

        job.setMapperClass(MultiFileMapper.class);
        job.setReducerClass(MultiFileReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(Text.class);

        job.setPartitionerClass(MultiPartitioner.class);
        job.setNumReduceTasks(1);


        Path[] inputPaths = new Path[]{
                new Path("F:/soft/edu-test/file1.txt"),
                new Path("F:/soft/edu-test/file2.txt"),
                new Path("F:/soft/edu-test/file3.txt")};
        String output = "F:\\soft\\edu-test\\output1";
        FileInputFormat.setInputPaths(job, inputPaths);
        FileOutputFormat.setOutputPath(job, new Path(output));

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);
    }
}
